<!DOCTYPE html>
<#assign dicSelect = JspTaglibs["http://www.casic304.cn/dicSelect"]/>
<#assign f = JspTaglibs["http://www.casic304.cn/f"] />
<#assign SourceDept = JspTaglibs["http://www.casic304.cn/SourceDept"]/>
<head>
    <meta charset="utf-8">
    <title>关联质量问题</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/style/qbdms.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body class="listBodyHeight">
<div class="qbdms-list qbdms-layer-list">
    <div class="">
        <table id="wQbdFalProblemresetTable" lay-filter="wQbdFalProblemresetTable"></table>
    </div>
</div>
<!-- 列表头部工具栏 -->
<script type="text/html" id="wQbdFalProblemresetHeaderToolsBar">
    <div class="ccpui-enterSel">
        <div class="layui-btn-container">

        </div>
        <form class="layui-form" action="" lay-filter="wQbdFalProblemresetQueryForm" >
            <div class="layui-form-body selch">
                <a class="layui-btn layui-btn-sm fillBtn" lay-event="associations">
                    <span>关联质量问题</span>
                </a>
                <a class="layui-btn layui-btn-sm" lay-event="associated" style="position: absolute;top: 8px;left: 126px;margin: 0;">
                    <span>已关联质量信息</span>
                </a>
                <div class="table-top-filter layui-row" style="margin-left: 274px;">
                    <div class=" layui-col-md12 layui-col-sm12" >
                        <label class="layui-form-label">质量问题名称</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input filter-value" name="Q_fProblemname_SL"
                                   placeholder="请输入"/>
                        </div>
                    </div>
                </div>

                <div class="selchBtn">
                    <a class="layui-btn layui-btn-sm fillBtn" lay-event="query">
                        <span>查询</span>
                    </a>
                    <div class="layui-btn-group">
                        <button type="button" class="layui-btn layui-btn-sm" lay-event="clears" style="width: 28px;font-size: 12px;padding: 0">
                            <i class="iconfont data-iconcommon_refresh"></i>
                        </button>
                    </div>
                </div>
            </div>
        </form >
    </div>
</script>
<!-- 右侧工具栏 -->
<script type="text/html" id="wQbdFalProblemresetRightToolsBar">
    <@f.a alias="xqan_zlwt3" css="RightBtn" event="particulars">详情</@f.a>
    <@f.a alias="xqan_zlwt3y" css="RightBtn" event="particularsSanYuan">详情</@f.a>
</script>
<script src="${ctx}/qbdmsStatic/public/configFile.js"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.config({
        base: serverPath.qbdmsPath + staticPath.qbdmsPath //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table', 'form', 'common','publicMethods','jquery','laydate', 'layer'], function () {
        var table = layui.table;
        var form = layui.form;
        var publicMethods = layui.publicMethods;
        var common = layui.common;
        var $ = layui.jquery;
        var layer = layui.layer;
        var totalFilter = layui.totalFilter;
        common.tableSort('wQbdFalProblemresetTable');
        var tableH = publicMethods.tabHeight('30');
        //第一个实例
        table.render({
            elem: '#wQbdFalProblemresetTable'
            ,url: serverPath.qbdmsPath + '/qbdms/wQbdFalProblemreset/list?mark=db'
            ,page: publicMethods.pageFun() //开启分页
            ,limit: 20
            ,defaultToolbar: ['']
            ,toolbar: '#wQbdFalProblemresetHeaderToolsBar'
            ,method: 'post'
            ,height: tableH
            ,autoSort: false //是否排序
            ,cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'sn', type: 'numbers', title: '序号', fixed: 'left'}
                ,{field: 'fProblemname', title: '质量问题名称', sortname: 'f_problemname'}
                ,{field: 'fModelsymbol', title: '型号代号', sortname: 'f_modelsymbol'}
                ,{field: 'fModelname', title: '型号名称', sortname: 'f_modelname'}
                ,{
                    fixed: 'right',
                    title: '管理',
                    toolbar: '#wQbdFalProblemresetRightToolsBar'
                }
            ]],done:function () {
                common.tableSelectCon('.ccpui-enterSel .layui-form input','a[lay-event=query]','.ccpui-enterSel');
            }
        });

        function reflashQuery(isClear) {
            common.tableConditionRender("wQbdFalProblemresetTable","wQbdFalProblemresetQueryForm",{where:{}},isClear);
        }

        function associated(){
            var layerH2=publicMethods.layHeight('.listBodyHeight');
            layer.open({
                type: 2,
                area: ['80%', layerH2],
                title: ['已关联信息'],
                fixed: false, //不固定
                maxmin: true,
                content: serverPath.qbdmsPath + '/qbdms/wQbdFalSupervise/view/associated?did=' + '${did}',
                end: function(){
                    reflashQuery(true);
                }
            });
        }

        function associations(datas){
            if(datas.length < 1){
                layer.open({
                    title: '提示信息'
                    ,content: "请选择一条数据"
                });
                return;
            }

            // 获取需要质量信息的id
            var ids = [];
            $.each(datas, function (index, obj) {
                ids.push(obj.id);
            });
            // 获取督办id
            var data = {"ids":ids.join(),"did":"${did}"};

            $.ajax({
                type: "POST",
                url: "${ctx}/qbdms/wQbdFalSupervise/associations",
                async: false, //改为同步请求
                contentType: 'application/x-www-form-urlencoded',
                data: data,
                dataType: "json",
                success: function (data) {
                    layer.msg(data.message,{title: false,skin: 'confirm-class'});
                    // layer.open({
                    //     title: '提示信息'
                    //     ,content: data.message
                    // });
                    // 执行重载
                    reflashQuery(true);
                },
                error: function () {
                    //函数体，数据发送错误时执行
                    layer.msg(data.message,{title: false,skin: 'confirm-class'});
                    reflashQuery(true);
                }
            });

        }

        table.on('toolbar(wQbdFalProblemresetTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            var _this = this;
            switch (obj.event) {
                case "query":
                    reflashQuery(false);
                    break;
                case "associations":
                    associations(data);
                    break;
                case "clears":
                    reflashQuery(true);
                    break;
                case "associated":
                    associated(data);
                    break;
            }
        });

        table.on('tool(wQbdFalProblemresetTable)', function(obj) {
            var data = obj.data, //获得当前行数据
                    layEvent = obj.event; //获得 lay-event 对应的值
            var layerH=publicMethods.layHeight(parent.document.getElementsByClassName('listBody')[0]);
            switch(layEvent){
                case "particulars":
                    parent.layer.open({
                        type: 2,
                        moveOut :true,
                        area: ['80%', layerH],
                        // btn:['关闭'],
                        move:false,
                        title: ['详情'],
                        content: serverPath.qbdmsPath + '/qbdms/wQbdFalProblemreset/view/particulars?id='+data.id+'&mark=db'
                    });
                    break;
                case "particularsSanYuan":
                    parent.layer.open({
                        type: 2,
                        moveOut :true,
                        area: ['80%', layerH],
                        // btn:['关闭'],
                        move:false,
                        title: ['详情'],
                        content: serverPath.qbdmsPath + '/qbdms/wQbdFalProblemreset/view/particularsSanYuan?id='+data.id+'&mark=db'
                    });
                    break;
            }
        });




    });
</script>
</body>
</html>